package com.blb.educourseservice.dldemo;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 订单超时处理监听器
 */
@Slf4j
@Component
public class OrderDeadLetterListener {

    //处理超时订单,绑定死信队列
    @RabbitListener(queues = RabbitMQConfig2.ORDER_DEAD_LETTER_QUEUE_NAME)
    public void handleTimeoutOrder(String text, Channel channel, Message message) throws IOException {
        if(OrderController.payed){
            log.info("购买商品{}成功！正在发货....",text);
        }else{
            log.info("支付时间超时，订单{}取消...",text);
        }
        //手动确认
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
